﻿#region Usings&Copyright
/*================================================
 *= Writer.cs (c)2009 Eagle Eye Studios          =
 *=         Written by Florian Vick              =
 *================================================
 */
using System;
using System.Collections.Generic;
using System.Text;
using Nini.Config;
#endregion

namespace Astudio.FileManagement
{
    public sealed class Writer
    {
        #region Variables
        /// <summary>
        /// Gets the Filepath of Current Menü
        /// </summary>
        public string Filepath { get; private set; }
        private DotNetConfigSource writer;
        #endregion

        #region Methods
        /// <summary>
        /// Creates a new Instance of Writer
        /// </summary>
        /// <param name="Path"></param>
        public Writer(string Path)
        {
            Filepath = Path;
            writer = new DotNetConfigSource();
            writer.AddConfig("Settings");
        }

        /// <summary>
        /// Writes the Name to a ConfigFile.
        /// </summary>
        /// <param name="Value">The Value to write.</param>
        public void WriteName(string Value)
        {
            try
            {
                writer.Configs["Settings"].Set("MenuName", Value);
            }
            catch { throw new Exception("Could not write Value @ Settings/MenuName"); }
        }

        /// <summary>
        /// Writes the Number of TotalElements
        /// </summary>
        /// <param name="tObjects">The number of Elements</param>
        public void WriteTotalObjects(int tObjects)
        {
            try { writer.Configs["Settings"].Set("TotalElements", tObjects); }
            catch { throw new Exception("Could not Write TotalElementsValue"); }
        }

        /// <summary>
        /// Writes the Design to the Configfile
        /// </summary>
        /// <param name="Design">The Design</param>
        public void WriteDesign(string Design)
        {
            try { writer.Configs["Settings"].Set("Design", Design); }
            catch { throw new Exception(); }
        }

        /// <summary>
        /// Writes if Windows is use or not
        /// </summary>
        /// <param name="useWindow"></param>
        public void WriteUseWindow(bool useWindow)
        {
            writer.Configs["Settings"].Set("UseWindow", useWindow);
        }

        /// <summary>
        /// Writes all Configs to a File
        /// </summary>
        public void FlushToFile()
        {
            try
            {
                writer.Save(Filepath);
            }
            catch
            {
                throw new Exception("Could not Save File");
            }
        }
        #endregion
    }
}
